package com.my.hotel.mapper;

import com.my.hotel.entity.Order;
import com.my.hotel.entity.OrderDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderMapper {

    // 查询个人订单信息
    @Select("<script>" +
            "select * from tb_order o,tb_kf_room r,tb_kf_type t where o.user_id = #{userId} " +
            "and o.`kf_id`=r.`id` and r.`kf_type_id`=t.`id`" +
            "<if test='orderStatus != null'>" +
            " and o.order_status=#{orderStatus}" +
            "</if>" +
            "<if test='evaStatus != null'>" +
            " and o.eva_status=#{evaStatus}" +
            " </if>"+
            "</script>")
    public List<OrderDTO> getOrderList(@Param("userId") int userId,@Param("orderStatus") String orderStatus,@Param("evaStatus") String evaStatus);

    // 修改点评状态
    @Update("update tb_order set eva_status=#{evaStatus} where id=#{orderId} ")
    public void updEvaStatus(@Param("evaStatus") String evaStatus,@Param("orderId") String orderId);

    //得到最大tb_order 的最大id
    @Select("select MAX(id) from tb_order")
    public int kf_order_maxId();

    //房间预定
    @Insert("insert into tb_order values(null,#{orderNum},#{orderStatus}," +
            "#{orderYdTime},#{orderRzTime},#{orderDay},#{userId},#{kfId},#{orderPayMoney},#{orderPayStatus},#{evaStatus})")
    public void kf_order(Order order);
}
